package org.smile.log.record;

import java.io.PrintWriter;


public class ConsoleHandler extends  AbstractHandler{
	
	@Override
	public void handle(LogRecord record,Throwable throwable) {
		if(needLog(record)){
			PrintWriter writer=openPrintWriter();
			writer.println(formatter.format(record));
			if (throwable != null) {
				throwable.printStackTrace(writer);
			}
		}
	}

	/**
	 *
	 * @return
	 */
	protected PrintWriter openPrintWriter(){
		if(this.outWriter==null){
			this.outWriter=new PrintWriter(System.out,true);
		}
		return this.outWriter;
	}

}
